#!/bin/bash

# int_speed=(perlbench_s gcc_s mcf_s omnetpp_s xalancbmk_s x264_s deepsjeng_s leela_s exchange2_s xz_s)
# fspeed=(bwaves_s cactuBSSN_s lbm_s wrf_s cam4_s pop2_s imagick_s nab_s fotonik3d_s roms_s)
# int_speed=(600.perlbench_s 602.gcc_s 605.mcf_s 620.omnetpp_s 623.xalancbmk_s 625.x264_s 631.deepsjeng_s 641.leela_s 648.exchange2_s 657.xz_s 603.bwaves_s 607.cactuBSSN_s 619.lbm_s 621.wrf_s 627.cam4_s 628.pop2_s 638.imagick_s 644.nab_s 649.fotonik3d_s 654.roms_s)
# cpu17=(500.perlbench_r 502.gcc_r 503.bwaves_r 505.mcf_r 507.cactuBSSN_r 508.namd_r
#         510.parest_r 511.povray_r 519.lbm_r 520.omnetpp_r 521.wrf_r
#         523.xalancbmk_r 525.x264_r 526.blender_r 527.cam4_r 531.deepsjeng_r 538.imagick_r
#         541.leela_r 544.nab_r 548.exchange2_r 549.fotonik3d_r
#         554.roms_r 557.xz_r
#         648.exchange2_s 641.leela_s 644.nab_s
#         638.imagick_s 654.roms_s 996.specrand_fs)

# cpu17=(500.perlbench_r  502.gcc_r   503.bwaves_r    505.mcf_r   507.cactuBSSN_r
#         508.namd_r      510.parest_r 511.povray_r   519.lbm_r   520.omnetpp_r
#         521.wrf_r       523.xalancbmk_r 525.x264_r  526.blender_r 527.cam4_r
#         531.deepsjeng_r 538.imagick_r   541.leela_r 544.nab_r 548.exchange2_r
#         549.fotonik3d_r 554.roms_r  557.xz_r)

# cpu17=(500.perlbench_r 502.gcc_r 505.mcf_r 520.omnetpp_r
#                 523.xalancbmk_r 525.x264_r 531.deepsjeng_r 541.leela_r 548.exchange2_r 557.xz_r
#                 503.bwaves_r 507.cactuBSSN_r 508.namd_r 510.parest_r 511.povray_r 519.lbm_r
#                 521.wrf_r 526.blender_r  527.cam4_r 538.imagick_r
#                 544.nab_r 549.fotonik3d_r 554.roms_r )


# cpu17Rate=(500.perlbench_r 502.gcc_r 505.mcf_r 520.omnetpp_r 523.xalancbmk_r 525.x264_r 
#         531.deepsjeng_r 541.leela_r 548.exchange2_r 557.xz_r 
#         503.bwaves_r 507.cactuBSSN_r 508.namd_r 510.parest_r 511.povray_r 519.lbm_r 521.wrf_r 
#         526.blender_r  527.cam4_r 538.imagick_r 544.nab_r 549.fotonik3d_r 554.roms_r)

# cpu17=(600.perlbench_s 602.gcc_s 605.mcf_s 620.omnetpp_s 623.xalancbmk_s 625.x264_s 631.deepsjeng_s
#                 641.leela_s 648.exchange2_s 657.xz_s 
#                 603.bwaves_s 607.cactuBSSN_s 619.lbm_s 621.wrf_s 627.cam4_s 
#                 628.pop2_s 638.imagick_s 644.nab_s 649.fotonik3d_s 654.roms_s)

# cpu17=(500.perlbench_r 502.gcc_r 505.mcf_r 520.omnetpp_r 523.xalancbmk_r 
#                 525.x264_r 531.deepsjeng_r 541.leela_r 548.exchange2_r 557.xz_r 
#                 503.bwaves_r 507.cactuBSSN_r 508.namd_r 510.parest_r 511.povray_r 
#                 519.lbm_r 521.wrf_r 526.blender_r  527.cam4_r 538.imagick_r 
#                 544.nab_r 549.fotonik3d_r 554.roms_r
#                 600.perlbench_s 602.gcc_s 605.mcf_s 620.omnetpp_s 623.xalancbmk_s 
#                 625.x264_s 631.deepsjeng_s 641.leela_s 648.exchange2_s 657.xz_s 
#                 603.bwaves_s 607.cactuBSSN_s 619.lbm_s 621.wrf_s 627.cam4_s 
#                 628.pop2_s 638.imagick_s 644.nab_s 649.fotonik3d_s 654.roms_s
#                 996.specrand_fs 997.specrand_fr 998.specrand_is 999.specrand_ir
#         )


cpu17=(600.perlbench_s 602.gcc_s 605.mcf_s 620.omnetpp_s 623.xalancbmk_s 
            625.x264_s 631.deepsjeng_s 641.leela_s 648.exchange2_s 657.xz_s 
            603.bwaves_s 607.cactuBSSN_s 619.lbm_s 621.wrf_s 627.cam4_s 
            628.pop2_s 638.imagick_s 644.nab_s 649.fotonik3d_s 654.roms_s
        )

SPEC_DIR=/home/jiangfang/workspace/benchmarks/cpu2017

type=(baselineM)

for t in "${!type[@]}"
do
    TYPE=${type[$t]}
    STATS_DIR=$SPEC_DIR/spec17_stats/$TYPE    # Run directory for the selected SPEC benchmark
    cd $STATS_DIR
    echo "CPI "
    for i in "${!cpu17[@]}"
    do
        BENCHMARK_CODE=${cpu17[$i]}
        RES=$BENCHMARK_CODE'_stats'
        sed -n -e '/^system.switch_cpus.cpi/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2
    done
done

# sed -n -e '/^system.cpu.numCycles/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2
# sed -n -e '/^system.switch_cpus.numCycles/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2

for t in "${!type[@]}"
do
    TYPE=${type[$t]}
    STATS_DIR=$SPEC_DIR/spec17_stats/$TYPE    # Run directory for the selected SPEC benchmark
    cd $STATS_DIR
    echo "L1 "
    for i in "${!cpu17[@]}"
    do
        BENCHMARK_CODE=${cpu17[$i]}
        RES=$BENCHMARK_CODE'_stats'
        sed -n -e '/^system.cpu.dcache.overallMissRate::total/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2
    done
done


for t in "${!type[@]}"
do
    TYPE=${type[$t]}
    STATS_DIR=$SPEC_DIR/spec17_stats/$TYPE    # Run directory for the selected SPEC benchmark
    cd $STATS_DIR
    echo "L2"
    for i in "${!cpu17[@]}"
    do
        BENCHMARK_CODE=${cpu17[$i]}
        RES=$BENCHMARK_CODE'_stats'
        sed -n -e '/^system.cpu.l2.overallMissRate::total/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2
    done
done




# for t in "${!type[@]}"
# do
#     TYPE=${type[$t]}
#     STATS_DIR=$SPEC_DIR/spec17_stats/$TYPE    # Run directory for the selected SPEC benchmark
#     cd $STATS_DIR
#     echo "numLoadInsts"
#     for i in "${!cpu17[@]}"
#     do
#         BENCHMARK_CODE=${cpu17[$i]}
#         RES=$BENCHMARK_CODE'_stats'
#         sed -n -e '/^system.switch_cpus.numLoadInsts/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2
#     done
# done

# for t in "${!type[@]}"
# do
#     TYPE=${type[$t]}
#     STATS_DIR=$SPEC_DIR/spec17_stats/$TYPE    # Run directory for the selected SPEC benchmark
#     cd $STATS_DIR
#     echo "numStoreInsts"
#     for i in "${!cpu17[@]}"
#     do
#         BENCHMARK_CODE=${cpu17[$i]}
#         RES=$BENCHMARK_CODE'_stats'
#         sed -n -e '/^system.switch_cpus.numStoreInsts/p' $RES.txt |tr -s [:blank:] | cut -d" " -f2
#     done
# done